package net.shopxx.entity;

import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import org.compass.annotations.Index;
import org.compass.annotations.SearchableProperty;
import org.compass.annotations.Store;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.sun.istack.internal.Nullable;

/**
 * 实体类 - 商品分类
 */

@Entity
public class ProductCategory extends BaseEntity {

	private static final long serialVersionUID = -5132652107151648662L;

	public static final String PATH_SEPARATOR = ",";// 树路径分隔符

	private String name;// 分类名称
	private String metaKeywords;// 页面关键词
	private String metaDescription;// 页面描述
	private String categroyIcon;//图标
	private Integer orderList;// 排序
	private String path;// 树路径
	private String htmlFilePath;
	
	private ProductCategory parent;// 上级分类
	private Set<ProductCategory> children;// 下级分类
	private Set<Product> productSet;// 商品
	
	private List<Brand> brandList;
	
	private Indexfloor indexfloor;
	
	private Set<Properties> propertiesSet;
	
	private Properties productSize;

	@Column(nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(length = 5000)
	public String getMetaKeywords() {
		return metaKeywords;
	}

	public void setMetaKeywords(String metaKeywords) {
		this.metaKeywords = metaKeywords;
	}

	@Column(length = 5000)
	public String getMetaDescription() {
		return metaDescription;
	}

	public void setMetaDescription(String metaDescription) {
		this.metaDescription = metaDescription;
	}

	@Column(nullable = false)
	public Integer getOrderList() {
		return orderList;
	}

	public void setOrderList(Integer orderList) {
		this.orderList = orderList;
	}

	@Column(nullable = true, length = 10000)
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	@SearchableProperty(index = Index.NO, store = Store.YES)
	@Column(nullable = false, updatable = false, length = 255)
	public String getHtmlFilePath() {
		return htmlFilePath;
	}

	public void setHtmlFilePath(String htmlFilePath) {
		this.htmlFilePath = htmlFilePath;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	public ProductCategory getParent() {
		return parent;
	}

	public void setParent(ProductCategory parent) {
		this.parent = parent;
	}

	@OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
	@OrderBy("orderList asc")
	public Set<ProductCategory> getChildren() {
		return children;
	}

	public void setChildren(Set<ProductCategory> children) {
		this.children = children;
	}
	
	@OneToMany(mappedBy = "productCategory", fetch = FetchType.LAZY)
	public Set<Product> getProductSet() {
		return productSet;
	}

	public void setProductSet(Set<Product> productSet) {
		this.productSet = productSet;
	}

	// 获取分类层级（顶级分类：0）
	@Transient
	public Integer getLevel() {
		return path.split(PATH_SEPARATOR).length - 1;
	}

	@Column(nullable = true, length = 255)
	public String getCategroyIcon() {
		return categroyIcon;
	}

	public void setCategroyIcon(String categroyIcon) {
		this.categroyIcon = categroyIcon;
	}

	@Transient
	public List<Brand> getBrandList() {
		return brandList;
	}

	public void setBrandList(List<Brand> brandList) {
		this.brandList = brandList;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@Nullable
    public Indexfloor getIndexfloor() {
        return indexfloor;
    }

    public void setIndexfloor(Indexfloor indexfloor) {
        this.indexfloor = indexfloor;
    }

    @ManyToMany(fetch = FetchType.LAZY)
	public Set<Properties> getPropertiesSet() {
		return propertiesSet;
	}

	public void setPropertiesSet(Set<Properties> propertiesSet) {
		this.propertiesSet = propertiesSet;
	} 
	
	@ManyToOne(fetch = FetchType.LAZY)
	@Cascade(value = { CascadeType.DELETE,CascadeType.SAVE_UPDATE})
	public Properties getProductSize() {
		return productSize;
	}

	public void setProductSize(Properties productSize) {
		this.productSize = productSize;
	}
	
	
    
    
	
	
	
	

}